﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WoBian.Models.Admin.User;
using WoBian.Controllers.Common;
using WoBian.Lib;
using System.IO;
namespace WoBian.Controllers.Admin
{
    public class AdminUserController : AdminController
    {
        //
        // GET: /AdminUser/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /AdminUser/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /AdminUser/Create

        [HttpPost]
        public ActionResult Create(AdminUserModel aModel)
        {
            try
            {
                // TODO: Add insert logic here
                HttpPostedFileBase file = Request.Files[0];
                aModel.Picture = new byte[file.ContentLength];
                file.InputStream.Read(aModel.Picture, 0, file.ContentLength);
                var item = new WoBian.Logic.Admin.User.AdminUserLogic();
                aModel.SaveAdminUser();
                return View(aModel);
            }
            catch(Exception ex)
            {
                return ShowErrorMessage(ex.Message);
            }
        }
        
        //
        // GET: /AdminUser/Edit/5
 
        public ActionResult Edit(string aUserId)
        {
            return View();
        }

        //
        // POST: /AdminUser/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /AdminUser/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /AdminUser/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
